package Sub;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;

public class Sub_J24ProfessorDAOImpl implements Sub_J24ProfessorDAO {

	private static String DRV = "oracle.jdbc.driver.OracleDriver";
	private static String URL = "jdbc:oracle:thin:jhlee183/jhlee183@112.216.253.124:1521:xe";
	//private static String URL = "jdbc:oracle:thin:siestageek/siestageek@"+ "112.216.253.124:1521:xe";
	//private static String URL = "jdbc:oracle:thin:scott/TIGER@"+ "112.216.253.124:1521:xe";
	
	private static String insertSQL = ""; 
	private static String selectSQL = " select * from professor order by pfno "; 
	private static String selectOneSQL = ""; 
	private static String updateSQL = ""; 
	private static String deleteSQL = ""; 
	
	@Override
	public String insertProfessor(Sub_J24ProfessorVO pvo) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public ArrayList<Sub_J24ProfessorVO> selectProfessor() {
		Connection conn = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		ArrayList<Sub_J24ProfessorVO> pvoes = null;
		
		try {
			conn = makeConn();
			pstmt = conn.prepareStatement(selectSQL);
			rs = pstmt.executeQuery();
			
			pvoes = new ArrayList<>();
			while(rs.next()) {
				Sub_J24ProfessorVO vo = new Sub_J24ProfessorVO(null,null,null);
					vo.setPfno( rs.getString(1) );
					vo.setPfname( rs.getString(2) );
					vo.setFields( rs.getString(3) );
					vo.setSkills( rs.getString(4) );
					vo.setRegdate( rs.getString(5) );
				pvoes.add( vo );
			}
			
		} catch (Exception ex) {ex.printStackTrace();
		} finally {closeConn( conn, pstmt, rs );}
		
		return pvoes;
	}

	@Override
	public ArrayList<Sub_J24ProfessorVO> selectOneProfessor(String pfno) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String updateProfessor(String pfno) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String deleteProfessor(String pfno) {
		// TODO Auto-generated method stub
		return null;
	}
	
	private void closeConn(Connection c, 
			PreparedStatement p, ResultSet r) {
		if ( r != null ) try { } catch (Exception e) { }
		if ( p != null ) try { } catch (Exception e) { }
		if ( c != null ) try { } catch (Exception e) { }
	}

	private Connection makeConn() 
				throws Exception {
		Connection conn = null;
		Class.forName(DRV);
		conn = DriverManager.getConnection(URL);
		return conn;
	}
}




